package com.admin.education.controllers.business;


import com.admin.education.common.exceptions.BadRequestException;
import com.admin.education.common.jwt.JwtAuthorize;
import com.admin.education.common.response.IResponseMessage;
import com.admin.education.common.response.ResponseMessageWithData;
import com.admin.education.common.response.Result;
import com.admin.education.dataTransferObject.ServicesExcuteResult;
import com.admin.education.dataTransferObject.role.RoleTransfer;
import com.admin.education.services.Interfaces.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.Callable;

@JwtAuthorize
@RestController("businessRoleController")
@RequestMapping("roles")
@CrossOrigin(origins = "*", maxAge = 3600)
public class RoleController {
    @Autowired
    private IRoleService roleService;
    @GetMapping("")
    public Callable<IResponseMessage> queryRoles(){
        return ()->{
            IResponseMessage responseMessage =null;

            ServicesExcuteResult<List<RoleTransfer>> result = this.roleService.queryRoles();
            if(result.isSuccess()){
                responseMessage = new ResponseMessageWithData<List<RoleTransfer>>(Result.Success,result.getData());
            }
            else
                throw new BadRequestException(result.getErrorMessage());
            return responseMessage;
        };
    }
}
